package com.bstek.bdf4.investigate;

import com.bstek.bdf4.investigate.entity.Category;
import com.bstek.bdf4.investigate.entity.Investigate;
import com.bstek.bdf4.investigate.service.CategoryService;
import com.bstek.bdf4.investigate.service.InvestigateService;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.provider.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class CategoryInvestigate {
    @Autowired
    CategoryService categoryService;
    @Autowired
    InvestigateService investigateService;

    @DataProvider
    public Collection<Category> getCategoryById(Long id) {
        return categoryService.getCategoryById(id);
    }

    /**
     * 通过分类查询该分类下报告
     */
    @DataProvider
    public void getInvestigateByCategoryId(Long id, Page<Investigate> page) {
        investigateService.getInvestigateByCategoryId(id, page);
    }

    @DataProvider
    public Collection<Category> getTopCategories() {
        return categoryService.getTopAll();
    }

    @DataResolver
    public void saveCategories(Collection<Category> categories) {
        categoryService.save(categories);
    }
}
